package common.interfaces;

import java.sql.SQLException;
import java.util.Collection;

import common.exceptions.InvalidKeyException;

/**
 * An interface for storing and restoring objects from the DB
 * 
 * @author Gal Lalouche
 * @param <T> The type of object saved
 * @param <Key> The key identifying the object
 */
public interface IDAL<T extends IHasId<Key>, Key> extends IPersistent {
	/**
	 * @param key The key to check
	 * @return <code>true</code> iff an item exists with the given key
	 * @throws SQLException
	 */
	boolean exists(Key key) throws SQLException;

	/**
	 * @param key The object's key
	 * @return The object if it exists
	 * @throws InvalidKeyException If no objects with they key
	 * @throws SQLException
	 */
	T get(Key key) throws InvalidKeyException, SQLException;

	/**
	 * Deletes the row with the given key
	 * 
	 * @param key The object's key
	 * @return <code>true</code> iff the row was successfully deleted
	 * @throws SQLException
	 */
	boolean delete(Key key) throws SQLException;

	/**
	 * @return All the objects stored
	 * @throws SQLException
	 */
	Collection<T> getAll() throws SQLException;
}
